<?php

class AdminAppModel extends AppModel {

    protected function upload($data, $prefix, $exception='upload fail')
    {
        if ($data['size'] == 0) {
            return '';
        }
        if (is_uploaded_file($data['tmp_name'])) {
            $folder = 'uploads/'.date('Ymd');
            if (!is_dir($folder)) {
                mkdir($folder);
            }
            $pathinfo = pathinfo($data['name']);
            $extension = $pathinfo['extension'];
            $filename = uniqid($prefix).'.'.$extension;
            $path = $folder.'/'.$filename;
            if (move_uploaded_file($data['tmp_name'], $path)) {
                return $path;
            }
        }
        throw new Exception($exception);

    }

}

